import { createStore } from "vuex";
import { post } from "@/api/index";
// 创建一个新的 store 实例
const store = createStore({
  state: {
    isLoading: false,
    token: undefined,
    loginopen: false,
    loginoreroll: "login",
    coinType: "BRL",
    lang: {
      img: "",
      name: "",
      lang: "",
    },
    coininfo: {
      brl: {
        totalCoins: 0,
        freezeCoins: 0,
        withdrawalCoins: 0,
        bonusCoins: 0,
        commissionCoins: 0,
      },
      usdt: {
        totalCoins: 0,
        freezeCoins: 0,
        withdrawalCoins: 0,
        bonusCoins: 0,
        commissionCoins: 0,
      },
    },
    info: {
      accounts: "",
      gameID: "",
      lastLogonDate: "",
      nickName: "",
      score: 0,
      spreaderCode: "",
    },
    Orderinfo: {
      orderNo: "",
      orderTime: "",
      payUrl: "",
      qrCode: "",
      timeout: 15,
    },
  },
  getters: {
    isLoading: (state) => state.isLoading,
    loginopen: (state) => state.loginopen,
    Orderinfo: (state) => state.Orderinfo,
    lang: (state) => state.lang,
  },
  mutations: {
    SET_LOADING(STATE, VAL) {
      STATE.isLoading = VAL;
    },
    SET_LOGIN(STATE, VAL) {
      STATE.loginopen = VAL;
    },
    SET_TOKEN(STATE, VAL) {
      STATE.token = VAL;
    },
    SET_LOGINOREROLL(STATE, VAL) {
      STATE.loginoreroll = VAL;
    },
    SET_INFO(STATE, VAL) {
      STATE.info = VAL;
    },
    SET_COINTYPE(STATE, VAL) {
      STATE.coinType = VAL;
    },
    SET_ORDERINFO(STATE, VAL) {
      STATE.Orderinfo = VAL;
    },
    SET_COININFO(STATE, VAL) {
      STATE.coininfo = VAL;
    },
    SET_LANG(STATE, VAL) {
      STATE.lang = VAL;
    },
  },
  actions: {
    GetUserInfo({ commit }, info) {
      return post("/Assets/v1.0/Account", { id: info.gameID });
    },
  },
});
export default store;
